package cn.itcast.account.service;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

/**
 * 声明TCC接口
 */
@LocalTCC
public interface AccountTccService {


    /**
     * try逻辑，资源检测与冻结,增加冻结金额，扣减可用余额
     * @param userId
     * @param money
     */
    @TwoPhaseBusinessAction(name = "deduct",commitMethod = "confirm",rollbackMethod = "cancel")
    void deduct(@BusinessActionContextParameter(paramName = "userId") String userId,
                @BusinessActionContextParameter(paramName = "money") int money);


    /**
     * 提交，扣减冻结金额
     * @param context
     * @return
     */
    boolean confirm(BusinessActionContext context);

    /**
     * 回滚,扣减冻结金额，增加可用余额
     * @param context
     * @return
     */
    boolean cancel(BusinessActionContext context);
}
